/*
 * FileName: SysLogsDao.java
 *
 */
package com.mrc.core.dao;

import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.stereotype.Repository;

import com.mrc.core.base.BaseDao;
import com.mrc.core.model.SysLogs;

/**
 * <p>
 * Description: 
 * </p>
 *
 * @author Mrc
 * @version 4.1

 * <p>
 * History: 
 *
 * Date                     Author         Version     Description
 * ---------------------------------------------------------------------------------
 * 2017-1-7 下午5:05:59          Mrc        4.1         To create
 * </p>
 *
 * @since 
 * @see     
 */
@Repository
public class SysLogsDao extends BaseDao<SysLogs> {

    protected SysLogsDao() {
        super(SysLogs.class);
    }

    /**
     * 根据账号，时间  获得用户的操作记录
     * @param account 账号
     * @param dateStr 开始时间  至  结束时间
     * @param logType 日志类型
     * @return
     */
    public List<SysLogs> listByAccount(String account, String dateStr, int logType) {
        StringBuilder sql = new StringBuilder("select * from sys_logs l where l.log_type= " + logType);
        if (StringUtils.isNotEmpty(account))
            sql.append(" and opt_person =" + account);
        if (StringUtils.isNotEmpty(dateStr)) {
            String[] dateArr = dateStr.split("至");
            sql.append(" and create_date between '").append(dateArr[0]).append(" 00:00:00' and '").append(dateArr.length > 1 ? dateArr[1] : dateArr[0]).append(" 23:59:59' ");
        }
        return super.querySQL(sql.toString());
    }

}
